"""
使用百度翻译API进行翻译
"""

import requests


# import json


def translate_word(word):
    url = 'https://fanyi.baidu.com/sug'
    data = {
        'kw': word
    }
    try:
        response = requests.post(url, data=data)
        response.raise_for_status()
        return response.json()
    except requests.RequestException as e:
        print("翻译失败：", e)
        return None


if __name__ == '__main__':
    word = input("请输入要翻译的单词：")
    result = translate_word(word)
    if result:
        print("翻译结果：", result['data'][0]['v'])
    else:
        print("未能获取翻译结果。")
